package cn.ctodb.mall.goods.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springframework.data.elasticsearch.annotations.Document;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import java.util.Objects;

import cn.ctodb.mall.goods.domain.enumeration.IsCheck;

/**
 * A Category.
 */
@Entity
@Table(name = "category")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "category")
public class Category implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "cat_name")
    private String catName;

    @Column(name = "cat_code")
    private String catCode;

    @Column(name = "keywords")
    private String keywords;

    @Column(name = "cat_desc")
    private String catDesc;

    @Column(name = "sort_order")
    private Integer sortOrder;

    @Column(name = "template_file")
    private String templateFile;

    @Column(name = "measure_unit")
    private String measureUnit;

    @Enumerated(EnumType.STRING)
    @Column(name = "show_in_nav")
    private IsCheck showInNav;

    @Column(name = "style")
    private String style;

    @Enumerated(EnumType.STRING)
    @Column(name = "is_show")
    private IsCheck isShow;

    @Column(name = "grade")
    private Integer grade;

    @Column(name = "icon_01")
    private String icon01;

    @OneToMany(mappedBy = "parent")
    @JsonIgnore
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    private Set<Category> children = new HashSet<>();

    @ManyToOne
    private Category parent;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCatName() {
        return catName;
    }

    public Category catName(String catName) {
        this.catName = catName;
        return this;
    }

    public void setCatName(String catName) {
        this.catName = catName;
    }

    public String getCatCode() {
        return catCode;
    }

    public Category catCode(String catCode) {
        this.catCode = catCode;
        return this;
    }

    public void setCatCode(String catCode) {
        this.catCode = catCode;
    }

    public String getKeywords() {
        return keywords;
    }

    public Category keywords(String keywords) {
        this.keywords = keywords;
        return this;
    }

    public void setKeywords(String keywords) {
        this.keywords = keywords;
    }

    public String getCatDesc() {
        return catDesc;
    }

    public Category catDesc(String catDesc) {
        this.catDesc = catDesc;
        return this;
    }

    public void setCatDesc(String catDesc) {
        this.catDesc = catDesc;
    }

    public Integer getSortOrder() {
        return sortOrder;
    }

    public Category sortOrder(Integer sortOrder) {
        this.sortOrder = sortOrder;
        return this;
    }

    public void setSortOrder(Integer sortOrder) {
        this.sortOrder = sortOrder;
    }

    public String getTemplateFile() {
        return templateFile;
    }

    public Category templateFile(String templateFile) {
        this.templateFile = templateFile;
        return this;
    }

    public void setTemplateFile(String templateFile) {
        this.templateFile = templateFile;
    }

    public String getMeasureUnit() {
        return measureUnit;
    }

    public Category measureUnit(String measureUnit) {
        this.measureUnit = measureUnit;
        return this;
    }

    public void setMeasureUnit(String measureUnit) {
        this.measureUnit = measureUnit;
    }

    public IsCheck getShowInNav() {
        return showInNav;
    }

    public Category showInNav(IsCheck showInNav) {
        this.showInNav = showInNav;
        return this;
    }

    public void setShowInNav(IsCheck showInNav) {
        this.showInNav = showInNav;
    }

    public String getStyle() {
        return style;
    }

    public Category style(String style) {
        this.style = style;
        return this;
    }

    public void setStyle(String style) {
        this.style = style;
    }

    public IsCheck getIsShow() {
        return isShow;
    }

    public Category isShow(IsCheck isShow) {
        this.isShow = isShow;
        return this;
    }

    public void setIsShow(IsCheck isShow) {
        this.isShow = isShow;
    }

    public Integer getGrade() {
        return grade;
    }

    public Category grade(Integer grade) {
        this.grade = grade;
        return this;
    }

    public void setGrade(Integer grade) {
        this.grade = grade;
    }

    public String getIcon01() {
        return icon01;
    }

    public Category icon01(String icon01) {
        this.icon01 = icon01;
        return this;
    }

    public void setIcon01(String icon01) {
        this.icon01 = icon01;
    }

    public Set<Category> getChildren() {
        return children;
    }

    public Category children(Set<Category> categories) {
        this.children = categories;
        return this;
    }

    public Category addChild(Category category) {
        this.children.add(category);
        category.setParent(this);
        return this;
    }

    public Category removeChild(Category category) {
        this.children.remove(category);
        category.setParent(null);
        return this;
    }

    public void setChildren(Set<Category> categories) {
        this.children = categories;
    }

    public Category getParent() {
        return parent;
    }

    public Category parent(Category category) {
        this.parent = category;
        return this;
    }

    public void setParent(Category category) {
        this.parent = category;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Category category = (Category) o;
        if (category.id == null || id == null) {
            return false;
        }
        return Objects.equals(id, category.id);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }

    @Override
    public String toString() {
        return "Category{" +
            "id=" + id +
            ", catName='" + catName + "'" +
            ", catCode='" + catCode + "'" +
            ", keywords='" + keywords + "'" +
            ", catDesc='" + catDesc + "'" +
            ", sortOrder='" + sortOrder + "'" +
            ", templateFile='" + templateFile + "'" +
            ", measureUnit='" + measureUnit + "'" +
            ", showInNav='" + showInNav + "'" +
            ", style='" + style + "'" +
            ", isShow='" + isShow + "'" +
            ", grade='" + grade + "'" +
            ", icon01='" + icon01 + "'" +
            '}';
    }
}
